home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 June
/
EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso
/
earcd
/
cmdity
/
yk212src.lha
/
Yak_2.12_Src
/
Prefs
/
gui.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-29
|
18KB
|
831 lines
/*
* GUI.c
*
* Contains high level common functions used by all the windows of Yak GUI
*
*/
#include <exec/execbase.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <diskfont/diskfont.h>
#include <graphics/text.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/gadtools.h>
#include <workbench/workbench.h>
#include <proto/exec.h>
#include <proto/diskfont.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/wb.h>
#include <string.h>
#ifdef MUI
#include <libraries/mui.h>
#include <proto/muimaster.h>
#endif
#ifdef BGUI
#include <libraries/bgui.h>
#include <libraries/bgui_macros.h>
#include <proto/bgui.h>
#include <clib/alib_protos.h>
#endif
#include "Code.h"
#include "yak.h"
#include "version.h"
#include "GetPubScreen.h"
#include "GetScreenBox.h"
#include "Hotkey_types.h"
#include "Root_window.h"
#include "MouseCycling_window.h"
#include "Options_window.h"
#include "KeyDef_window.h"
#include "Blank_window.h"
#include "Misc_window.h"
#include "Hotkey_window.h"
#include "DigitalClock_window.h"
#include "Requesters.h"
#include "Settings.h"
#include "gui.h"
#include "yak_locale_strings.h"
IMPORT struct MsgPort *AppMsgPort;
#ifdef BETA_VERSION
static UBYTE DisplayBetaRequester = TRUE;
#endif
struct Window *curwin = NULL;
UBYTE curwinID = ROOT_WINDOW;
#ifdef MUI
APTR *curwinobj = NULL;
#endif
#ifdef BGUI
Object *curwinobj = NULL;
struct TextAttr Attr;
char FontName[50];
int FontSize;
struct TextFont *TextFont = NULL;
UBYTE *PubScreenName = NULL;
ULONG appwinsigflag = 0;
#endif
IMPORT APTR App;
#ifdef GADTOOLS /* GadTools Specific Code */
struct Screen *Scr = NULL;
UBYTE *PubScreenName;
APTR VisualInfo = NULL;
struct TextAttr *Font,Attr;
UWORD FontX,FontY;
UWORD OffX,OffY;
WORD WindowTop = 0;
WORD WindowLeft = 0;
char FontName[50];
int FontSize;
static struct TextFont *TextFont=NULL;
int
SetupScreen(VOID)
{
struct Screen *s;
ULONG lock;
/* Choose a public screen to open our window */
lock = LockIBase(0);
s = IntuitionBase->ActiveScreen;
UnlockIBase(lock);
PubScreenName = GetPubScreenName(s);
if (! (Scr = LockPubScreen(PubScreenName)))
return(1L);
ScreenToFront(Scr);
ComputeFont(0,0);
if (! (VisualInfo = GetVisualInfo(Scr,TAG_DONE)))
return(2L);
return(0L);
}
void
CloseDownScreen(VOID)
{
if (VisualInfo) {
FreeVisualInfo(VisualInfo);
VisualInfo = NULL;
}
if (Scr) {
UnlockPubScreen(NULL,Scr);
Scr = NULL;
}
}
UWORD
ComputeX(UWORD value)
{
return((UWORD)(((FontX*value)+4)/8));
}
UWORD
ComputeY(UWORD value)
{
return((UWORD)(((FontY*value)+4)/8));
}
VOID
UseTopaz(VOID)
{
Font->ta_Name = (STRPTR)"topaz.font";
FontX = FontY = Font->ta_YSize = 8;
}
UWORD
CalcFontX(struct TextFont *TFont)
{
static struct RastPort DummyRastPort;
UWORD result;
if (TFont)
{
/* compute font width for the specified font */
SetFont(&DummyRastPort, TextFont);
result = (UWORD)TextLength(&DummyRastPort,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",52)/52 ;
}
else
{
/* compute font width for screen font */
result = (UWORD)TextLength(&Scr->RastPort,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",52)/52 ;
}
return(result);
}
VOID
ComputeFont(UWORD width,UWORD height)
{
Font = &Attr;
OffX = Scr->WBorLeft;
OffY = Scr->RastPort.TxHeight +Scr->WBorTop +1;
if (strlen(FontName)>0)
{
Font->ta_Name = (STRPTR)FontName;
Font->ta_YSize = FontY = (UWORD)FontSize;
}
else
{
Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
}
if (TextFont)
{
CloseFont(TextFont);
}
TextFont = OpenDiskFont(Font);
FontX = CalcFontX(TextFont);
/* Don't go under 8 points */
if (FontY < 8) FontY = 8;
if (width && height)
{
if (((ComputeX(width) + OffX + Scr->WBorRight) > Scr->Width) ||
((ComputeY(height) + OffY + Scr->WBorBottom) > Scr->Height) ||
(TextFont == NULL))
{
UseTopaz();
}
}
}
__regargs void
DrawThinBevelBox(struct Screen *Screen, struct RastPort *rp,
long Left, long Top, long Width, long Height, BOOL Recess)
{
struct DrawInfo *ScreenDrawInfo;
ScreenDrawInfo = GetScreenDrawInfo(Screen);
SetAPen(rp, ScreenDrawInfo->dri_Pens[(Recess) ? SHADOWPEN : SHINEPEN]);
Move(rp, Left, Top + Height - 1);
Draw(rp, Left, Top);
Draw(rp, Left + Width - 1, Top);
SetAPen(rp, ScreenDrawInfo->dri_Pens[(Recess) ? SHINEPEN : SHADOWPEN]);
Draw(rp, Left + Width - 1, Top + Height - 1);
Draw(rp, Left + 1, Top + Height - 1);
FreeScreenDrawInfo(Screen, ScreenDrawInfo);
}
/* Localize gadget labels, locale strings identifiers are stored in UserData filed */
__regargs void
LocalizeNGadLabels (UBYTE Gadgets_Num, struct NewGadget *NGad)
{
UWORD i;
for (i=0; i<Gadgets_Num; i++)
{
if (NGad[i].ng_UserData)
{
NGad[i].ng_GadgetText = getString(NGad[i].ng_UserData);
}
}
}
static __regargs VOID
SetWindowUnderMouse (UWORD Width, UWORD Height, WORD *Left, WORD *Top)
{
WORD MouseY, MouseX;
/* Where is our mouse pointer? */
MouseX = Scr->MouseX;
MouseY = Scr->MouseY;
/* Is our pointer above the window to open ? */
if ((MouseX >= *Left) && (MouseX <= (*Left+Width)) &&
(MouseY >= *Top) && (MouseY <= (*Top+Height)))
{
/* Yes, so we don't have to move our window */
}
else
{
/* No, so we have to move our window only by what is needed */
if ((MouseX < *Left) || (MouseX > (*Left+Width)))
*Left = MouseX - Width;
if ((MouseY < *Top) || (MouseY > (*Top+Height)))
*Top = MouseY - Height;
}
}
__regargs void
SetUpWindowCoordinates( UWORD Width, UWORD Height, WORD *Left, WORD *Top)
{
struct IBox box;
/* If AutoPoint is enabled, we want the window to be openned
* under mouse pointer
*/
if (autopoint)
SetWindowUnderMouse (Width, Height, Left, Top);
/* Check boundaries, especially for autoscroll screens */
GetScreenBox(Scr, &box, TRUE);
if (*Left < box.Left)
*Left = box.Left;
if (*Top < box.Top)
*Top = box.Top;
if ((*Left + Width) > box.Left + box.Width)
*Left = box.Left + box.Width - Width;
if ((*Top + Height) > box.Top + box.Height)
*Top = box.Top + box.Height - Height;
}
#endif /* GadTools Specific Code */
#ifdef BGUI /* BGUI specific code NMC */
int SetupScreen(VOID)
{
struct Screen *s;
ULONG lock;
/* Choose a public screen to open our window */
lock = LockIBase(0);
s = IntuitionBase->ActiveScreen;
UnlockIBase(lock);
PubScreenName = GetPubScreenName(s);
return(0L);
}
#endif
/* initialise individual gadget in specified window */
#ifdef GADTOOLS /* GadTools Version */
__regargs void
InitWindowGadget(UWORD num, LONG tagtype, LONG tagvalue, UBYTE WindowID)
{
switch(WindowID)
{
case ROOT_WINDOW:
GT_SetGadgetAttrs(RootGadgets[num], RootWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case HOTKEY_WINDOW:
GT_SetGadgetAttrs(HotKeyGadgets[num], HotKeyWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case MISC_WINDOW:
GT_SetGadgetAttrs(MiscGadgets[num], MiscWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case BLANK_WINDOW:
GT_SetGadgetAttrs(BlankGadgets[num], BlankWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case MCYCLING_WINDOW:
GT_SetGadgetAttrs(MouseCyclingGadgets[num], MouseCyclingWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case KEYDEF_WINDOW:
GT_SetGadgetAttrs(KeyDefGadgets[num], KeyDefWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case DIGITALCLOCK_WINDOW:
GT_SetGadgetAttrs(DigitalClockGadgets[num], DigitalClockWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
}
}
#endif
#ifdef MUI /* MUI version */
__regargs void
InitWindowGadget(UWORD num, LONG tagtype, LONG tagvalue, UBYTE WindowID)
{
switch(WindowID)
{
case ROOT_WINDOW:
SetAttrs(RootObjects[num], MUIA_NoNotify, TRUE, tagtype, tagvalue, TAG_DONE);
break;
case HOTKEY_WINDOW:
SetAttrs(HotKeyObjects[num], MUIA_NoNotify, TRUE, tagtype, tagvalue, TAG_DONE);
break;
case MISC_WINDOW:
SetAttrs(MiscObjects[num], MUIA_NoNotify, TRUE, tagtype, tagvalue, TAG_DONE);
break;
case BLANK_WINDOW:
SetAttrs(BlankObjects[num], MUIA_NoNotify, TRUE, tagtype, tagvalue, TAG_DONE);
break;
case MCYCLING_WINDOW:
SetAttrs(MouseCyclingObjects[num], MUIA_NoNotify, TRUE, tagtype, tagvalue, TAG_DONE);
break;
case KEYDEF_WINDOW:
SetAttrs(KeyDefObjects[num], MUIA_NoNotify, TRUE, tagtype, tagvalue, TAG_DONE);
break;
}
}
#endif
#ifdef BGUI /* BGUI version NMC */
__regargs void
InitWindowGadget(UWORD num, LONG tagtype, LONG tagvalue, UBYTE WindowID)
{
switch(WindowID)
{
case ROOT_WINDOW:
SetGadgetAttrs((struct Gadget *)RootObjects[num], RootWnd, NULL,
tagtype, tagvalue, TAG_DONE);
break;
case BLANK_WINDOW:
SetGadgetAttrs((struct Gadget *)BlankObjects[num], BlankWnd, NULL,
tagtype, tagvalue, TAG_DONE);
break;
case MISC_WINDOW:
SetGadgetAttrs((struct Gadget *)MiscObjects[num], MiscWnd, NULL,
tagtype, tagvalue, TAG_DONE);
break;
case MCYCLING_WINDOW:
SetGadgetAttrs((struct Gadget *)MouseCyclingObjects[num], MouseCyclingWnd, NULL,
tagtype, tagvalue, TAG_DONE);
break;
case HOTKEY_WINDOW:
SetGadgetAttrs((struct Gadget *)HotKeyObjects[num], HotKeyWnd, NULL,
tagtype, tagvalue, TAG_DONE);
break;
case KEYDEF_WINDOW:
SetGadgetAttrs((struct Gadget *)KeyDefObjects[num], KeyDefWnd, NULL,
tagtype, tagvalue, TAG_DONE);
break;
case DIGITALCLOCK_WINDOW:
SetGadgetAttrs((struct Gadget *)DigitalClockObjects[num], DigitalClockWnd, NULL,
tagtype, tagvalue, TAG_DONE);
break;
}
}
#endif
/* Init Toggles: Shared Code */
#ifdef GADTOOLS
# define CHECKMARK_TAG GTCB_Checked
#endif
#ifdef MUI
# define CHECKMARK_TAG MUIA_Selected
#endif
#ifdef BGUI /* NMC */
# define CHECKMARK_TAG GA_Selected
#endif
__regargs void
InitToggleGadgets( UBYTE WindowID )
{
UWORD i;
for (i = 0; i < NUM_TOGGLES; i++)
if ((toggles[i].gadid != OBSOLETE_TOGGLE) &&
(toggles[i].winid == WindowID))
{
InitWindowGadget(toggles[i].gadid,
CHECKMARK_TAG,
toggles[i].pos,
WindowID);
}
}
/* Handle pattern string-gadget */
#ifdef GADTOOLS /* GadTools Version */
__regargs void
NewPattern(UWORD gdx, PatternData *pdata, struct Gadget *gad, UBYTE WindowID)
{
char *newpatstr;
newpatstr = GetString(gad);
if (!InitPattern(newpatstr, pdata))
{
InitWindowGadget(gdx, GTST_String, (LONG)pdata->patstr, WindowID);
}
}
#endif
#ifdef MUI /* MUI Version */
__regargs void
NewPattern(UWORD gdx, PatternData *pdata, struct Gadget *gad, UBYTE WindowID)
{
char *newpatstr;
GetAttr(MUIA_String_Contents, gad, (ULONG *)&newpatstr);
if (!InitPattern(newpatstr, pdata))
{
InitWindowGadget(gdx, MUIA_String_Contents, (LONG)pdata->patstr, WindowID);
}
}
#endif
#ifdef BGUI /* BGUI Version NMC */
__regargs void
NewPattern(UWORD gdx, PatternData *pdata, struct Gadget *gad, UBYTE WindowID)
{
char *newpatstr;
GetAttr(STRINGA_TextVal, gad, (ULONG *)&newpatstr);
if (!InitPattern(newpatstr, pdata))
{
InitWindowGadget(gdx, STRINGA_TextVal, (LONG)pdata->patstr, WindowID);
}
}
#endif
/* Disable/Enable the GUI */
#ifdef GADTOOLS /* GadTools Version */
/* Wait pointer image data */
__chip static UWORD WaitPointer[] = {
0x0000, 0x0000,
0x0400, 0x07c0,
0x0000, 0x07c0,
0x0100, 0x0380,
0x0000, 0x07e0,
0x07c0, 0x1ff8,
0x1ff0, 0x3fec,
0x3ff8, 0x7fde,
0x3ff8, 0x7fbe,
0x7ffc, 0xff7f,
0x7efc, 0xffff,
0x7ffc, 0xffff,
0x3ff8, 0x7ffe,
0x3ff8, 0x7ffe,
0x1ff0, 0x3ffc,
0x07c0, 0x1ff8,
0x0000, 0x07e0,
0x0000, 0x0000
};
static struct Requester DummyReq;
static ULONG IDCMPFlags;
void
DisableYakInterface(VOID)
{
if (curwin)
{
/* Disable IDCMP */
IDCMPFlags = ((struct Window *)curwin)->IDCMPFlags;
ModifyIDCMP(curwin, IDCMP_REFRESHWINDOW);
/* Init dummy requester structure */
InitRequester(&DummyReq);
/* Block window input */
Request(&DummyReq, curwin);
/* Set wait pointer */
if (SysBase->LibNode.lib_Version >= 39)
SetWindowPointer(curwin, WA_BusyPointer, TRUE, TAG_DONE);
else
SetPointer(curwin, WaitPointer, 16, 16, -6, 0);
}
}
void
EnableYakInterface(VOID)
{
/* Clear wait pointer */
if (SysBase->LibNode.lib_Version >= 39)
SetWindowPointer(curwin, TAG_DONE);
else
ClearPointer(curwin);
/* Enable window input */
EndRequest(&DummyReq, curwin);
/* Enable IDCMP */
ModifyIDCMP(curwin, IDCMPFlags);
}
#endif
#ifdef MUI /* MUI Version */
void
DisableYakInterface(VOID)
{
set(App, MUIA_Application_Sleep, TRUE);
}
void
EnableYakInterface(VOID)
{
set(App, MUIA_Application_Sleep, FALSE);
}
#endif
#ifdef BGUI /* BGUI Version NMC */
void
DisableYakInterface(VOID)
{
WindowBusy(curwinobj);
}
void
EnableYakInterface(VOID)
{
WindowReady(curwinobj);
}
#endif
/* show current window */
BOOL
ShowYakInterface(VOID)
{
BOOL OK;
#ifdef BETA_VERSION
if (DisplayBetaRequester == TRUE)
{
PostError("This is " VERSION_NAME " beta version\nBuilt on " __DATE__);
DisplayBetaRequester = FALSE;
}
#endif
if (curwin) /* already opened */
{
ScreenToFront(((struct Window *)curwin)->WScreen);
WindowToFront(curwin);
ActivateWindow(curwin);
return TRUE;
}
#ifndef MUI
if (!(OK=SetupScreen()))
{
OK = ShowWindowID(curwinID);
}
#else
OK = ShowWindowID(curwinID);
#endif
if (!OK)
PostError(getString(Couldnt_open_GUI_ERR));
return(OK);
}
BOOL
ShowWindowID(UBYTE WindowID)
{
BOOL OK;
switch(WindowID)
{
case ROOT_WINDOW:
OK = ShowRootWindow();
break;
case HOTKEY_WINDOW:
OK = ShowHotKeyWindow();
break;
case MISC_WINDOW:
OK = ShowMiscWindow();
break;
case BLANK_WINDOW:
OK = ShowBlankWindow();
break;
case MCYCLING_WINDOW:
OK = ShowMouseCyclingWindow();
break;
case KEYDEF_WINDOW:
OK = ShowKeyDefWindow();
break;
case OPTIONS_WINDOW:
OK = ShowOptionsWindow();
break;
case DIGITALCLOCK_WINDOW:
OK = ShowDigitalClockWindow();
break;
}
if (OK)
{
ActivateWindow(curwin);
}
else
{
PostError(getString(Couldnt_open_other_window_ERR));
}
return(OK);
}
VOID
CloseWindowID(UBYTE WindowID)
{
switch(WindowID)
{
case ROOT_WINDOW:
CloseRootWindow();
break;
case HOTKEY_WINDOW:
CloseHotKeyWindow();
break;
case MISC_WINDOW:
CloseMiscWindow();
break;
case BLANK_WINDOW:
CloseBlankWindow();
break;
case KEYDEF_WINDOW:
CloseKeyDefWindow();
break;
case MCYCLING_WINDOW:
CloseMouseCyclingWindow();
break;
case OPTIONS_WINDOW:
CloseOptionsWindow();
break;
case DIGITALCLOCK_WINDOW:
CloseDigitalClockWindow();
break;
}
curwin = NULL;
#if defined(MUI) || defined(BGUI)
curwinobj = NULL;
#endif
}
#ifdef GADTOOLS /* GadTools Version */
void
CloseOneWindow (struct Window *Wnd,
struct Menu *Menus, struct Gadget *GList, struct AppWindow *AppWin)
{
/* Save coordinates of current window */
WindowTop = Wnd->TopEdge;
WindowLeft = Wnd->LeftEdge;
if (AppWin)
{
RemoveAppWindow(AppWin);
}
FreeMenus(Menus);
if (Wnd)
{
ClearMenuStrip(Wnd);
CloseWindow(Wnd);
}
FreeGadgets(GList);
}
#endif
#ifdef MUI /* MUI Version */
#endif
#ifdef BGUI /* BGUI Version NMC */
#endif
/* hide our window */
void
HideInterface(VOID)
{
if (curwin)
{
CloseWindowID(curwinID);
#ifdef GADTOOLS
CloseDownScreen();
#endif
}
#ifdef GADTOOLS
if (TextFont)
{
CloseFont(TextFont);
}
#endif
}